<%--
  Created by IntelliJ IDEA.
  User: lt
  Date: 2018/5/24
  Time: 20:42
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro" %>

<c:set var="contextPath" value="${pageContext.request.contextPath}"></c:set>
<c:set var="id" value="${pageContext.request.getParameter('id')}"></c:set>

<title>门店 - 调拨要货单商品详情</title>

<%--<link rel="stylesheet" href="${contextPath}/static/layer/css/layui.css" media="all">--%>
<link rel="stylesheet" href="${contextPath}/static/ace/components/_mod/jquery-ui/jquery-ui.css"/>
<%--<link rel="stylesheet" href="${contextPath}/static/statistics/css/bootstrap-datetimepicker.min.css">--%>
<link rel="stylesheet"
      href="${contextPath}/static/ace/components/bootstrap-datepicker/dist/css/bootstrap-datepicker3.css"/>
<link rel="stylesheet" href="${contextPath}/static/ace/components/_mod/jqgrid/ui.jqgrid.css"/>
<script src="${contextPath}/static/statistics/js/bootstrap-datetimepicker.min.js"></script>
<%--<script src="${contextPath}/static/statistics/js/bootstrap-datetimepicker.fr.js"></script>--%>
<script src="${contextPath}/static/statistics/js/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="${contextPath}/static/statistics/js/vue.js"></script>
<script src="${contextPath}/static/countjs/regularYz.js"></script>
<%--<jsp:include page="../../head.jsp"/>--%>
<style type="text/css">
    .customBtn {
        line-height: 20px;
        margin-bottom: 3px;
    }

    .btnLine {
        margin-left: 1px;
        margin-top: 8px;
        margin-bottom: 2px;
    }

    @-webkit-keyframes bouncedelay {
        0%, 80%, 100% {
            -webkit-transform: scale(0.0)
        }
        40% {
            -webkit-transform: scale(1.0)
        }
    }

    @keyframes bouncedelay {
        0%, 80%, 100% {
            transform: scale(0.0);
            -webkit-transform: scale(0.0);
        }
        40% {
            transform: scale(1.0);
            -webkit-transform: scale(1.0);
        }
    }

    .autocomplete-suggestions {
        border: 1px solid #999;
        background: #FFF;
        overflow: auto;
    }

    .autocomplete-suggestion {
        padding: 2px 5px;
        white-space: nowrap;
        overflow: hidden;
    }

    .autocomplete-selected {
        background: #F0F0F0;
    }

    .autocomplete-suggestions strong {
        font-weight: normal;
        color: #3399FF;
    }

    @-moz-document url-prefix() {
        fieldset {
            display: table-cell;
        }
    }

    .ui-jqgrid-sortable {
        text-align: center;
    }

    .SelectBG{
        background-color:red;
    }
</style>
<div class="row" id="app">
    <div class="row btnLine">
        <div class="button-len col-sm-12">
            <div style="width: 100%; margin-bottom: 10px;">
                <%--<button class="btn btn-white btn-sm btn-purple customBtn"  id="addProduct">--%>
                    <%--<i class="ace-icon fa fa-plus-circle purple"></i> 新增商品--%>
                <%--</button>--%>
                <%--<button class="btn btn-white btn-info btn-sm customBtn" id="editShop">--%>
                    <%--<i class="ace-icon fa fa-pencil blue"></i> 修改--%>
                <%--</button>--%>
                <%--<button class="btn btn-white btn-info btn-sm customBtn" id="zhip">--%>
                    <%--<i class="ace-icon fa fa-key red"></i> 仓配--%>
                <%--</button>--%>
                <shiro:hasPermission name="ALLOT:DIAOB:ADD">
                    <button class="btn btn-white btn-info btn-sm customBtn" id="diaob">
                        <i class="ace-icon fa fa-pencil blue"></i> 调拨
                    </button>
                </shiro:hasPermission>
                <%--<button class="btn btn-white btn-info btn-sm customBtn" id="faqi">--%>
                    <%--<i class="ace-icon fa fa-key red"></i> 发起要货--%>
                <%--</button>--%>
                <%--<button class="btn btn-white btn-info btn-sm customBtn" id="">--%>
                <%--<i class="ace-icon fa fa-key red"></i> 复制--%>
                <%--</button>--%>
                <%--<button class="btn btn-white btn-info btn-sm customBtn" id="">--%>
                <%--<i class="ace-icon fa fa-key red"></i> 打印--%>
                <%--</button>--%>
                <%--<button class="btn btn-white btn-info btn-sm customBtn" id="">--%>
                <%--<i class="ace-icon fa fa-key red"></i> 导出--%>
                <%--</button>--%>
                <%--<button class="btn btn-white btn-info btn-sm customBtn" id="">--%>
                <%--<i class="ace-icon fa fa-key red"></i> 设置--%>
                <%--</button>--%>
                <%--<a href="${contextPath}/sys/user/home#page/franchiseeShopAllot-orders">--%>
                    <button class="btn btn-white btn-info btn-sm customBtn" id="" onclick="javascript:window.history.go(-1);window.close();">
                        <i class="ace-icon fa fa-key red"></i> 返回
                    </button>
                <%--</a>--%>

            </div>
            <input class="input-sm" type="text" id="keyword" style="margin-left: 0px;" value=""
                   placeholder="关键字">
            <button class="btn btn-sm btn-white btn-info search-len customBtn"
                    onclick="searchShop()">
                <i class="ace-icon fa fa-search orange"></i>搜索
            </button>
            <div style="text-align: right;color: red;">
                <h3>{{ shopName }}</h3>
            </div>
        </div>
    </div>
    <!-- 内容数据开始 -->
    <div class="col-xs-12">
        <table id="grid-table"></table>

        <div id="grid-pager"></div>

    </div>

    <!-- 内容数据结束 -->

    <!-- 模态框（Modal） -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog" style="">
            <div class="modal-content">
                <div class="modal-header" style="font-size: 20px; margin-bottom: -15px;">
                    <h4 class="modal-title" id="myModalLabel">
                        调拨订单 - <span id="alertTitle">商品新增</span>
                        <small id="smallTitle" class="hide" style="color: red; float: right; margin-top: 10px;"></small>

                    </h4>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <table class="table">
                            <tbody>
                            <tr>
                                <th>
                                    <div class="row btnLine">
                                        <div class="button-len col-sm-12">
                                            <label for="" style="margin-left: 8px;">商品类型：</label>
                                            <select class="input-sm" id="isExpInput">
                                                <option value="0">商品类型</option>
                                                <option :value="obj.typeId" v-for="(obj, index) in yanType1">
                                                    {{ obj.typeName }}
                                                </option>

                                            </select>
                                            <select class="input-sm" id="isAuthInput">
                                                <option value="-1">商品大类</option>
                                                <option :value="obj.typeId" v-for="(obj, index) in yanType2">
                                                    {{ obj.typeName }}
                                                </option>
                                            </select>

                                            <select class="input-sm" id="isAuthInput1">
                                                <option value="-1">商品中类</option>
                                                <option :value="obj.typeId" v-for="(obj, index) in yanType3">
                                                    {{ obj.typeName }}
                                                </option>
                                            </select>

                                            <select class="input-sm" id="isAuthInput2">
                                                <option value="-1">商品小类</option>
                                                <option :value="obj.typeId" v-for="(obj, index) in yanType4">
                                                    {{ obj.typeName }}
                                                </option>
                                            </select>
                                        </div>
                                    </div>
                                </th>
                            </tr>
                            <tr>
                                <th>
                                    <input class="input-sm" type="text" id="productCode" style="margin-left: 20px;"
                                           placeholder="商品条码">
                                    <input class="input-sm" type="text" id="productName" style="margin-left: 5px;"
                                           placeholder="商品名称">
                                    <button class="btn btn-sm btn-white btn-info search-len customBtn"
                                            v-on:click="">
                                        <i class="ace-icon fa fa-search orange"></i>搜索
                                    </button>
                                </th>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                    <!-- 内容数据开始 -->
                    <div class="button-len col-sm-12" style="margin-bottom: 10px;">
                        <table id="grid-shop-table"></table>
                        <div id="grid-shop-pager"></div>
                    </div>
                    <%--<!-- 内容数据结束 -->--%>
                    <%--<div style="text-align: right;">--%>
                        <%--<button class="btn btn-white btn-info btn-sm customBtn btn-xs" type="button" onclick="submitCtyShop()">生成</button>--%>
                    <%--</div>--%>
                </div>
                <%--<div class="modal-footer">--%>
                    <%--<button type="button" class="btn btn-default btn-xs" data-dismiss="modal" v-on:click="close">关闭</button>--%>
                    <%--&lt;%&ndash;<button type="button" class="btn btn-primary btn-xs" v-on:click="saveSupplier">提交更改</button>&ndash;%&gt;--%>
                <%--</div>--%>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>
    <!-- 模态框（Modal） -->
    <div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        &times;
                    </button>
                    <h4 class="modal-title" id="myModalLabel1">
                        <span id="alertTitle1">价格下发 - 店铺选择</span>
                        <small id="smallTitle1" class="hide" style="color: red; float: right; margin-top: 10px;">哈哈哈</small>
                    </h4>
                </div>
                <div class="modal-body" id="submitCommodity">
                    <div class="button-len col-sm-12">
                        <label for="" style="">店铺类型：</label>
                        <select class="input-sm" id="shopType">
                            <option value="">请选择</option>
                            <option value="直营">直营</option>
                            <option value="加盟">加盟</option>
                        </select>

                        <input class="input-sm" type="text" id="shopName" style="margin-left: 2px;" placeholder="店铺名称">
                        <button class="btn btn-sm btn-white btn-info search-len customBtn" onclick="searchShopInfo()">
                            <i class="ace-icon fa fa-search orange"></i>搜索
                        </button>
                    </div>

                    <div class="button-len col-sm-12">
                        <table id="grid-shop1-table"></table>
                        <div id="grid-shop1-pager"></div>
                    </div>

                    <%--<div style="margin-top: 10px; text-align: right;">--%>
                    <%--<button class="btn btn-white btn-info btn-sm customBtn btn-xs" type="button" onclick="submitCtyShop()">下发</button>--%>
                    <%--</div>--%>
                </div>

                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                    </button>
                    <%--<button type="button" class="btn btn-primary">--%>
                    <%--提交更改--%>
                    <%--</button>--%>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>
</div>

<input type="text" name="fileStr" id="fileStr" style="display:none"/>
<input type="text" name="fileType" id="fileType" style="display:none"/>

<input type="text" name="fileStr1" id="fileStr1" style="display:none"/>
<input type="text" name="fileType1" id="fileType1" style="display:none"/>

<!-- page specific plugin scripts -->
<script type="text/javascript" src="${contextPath}/static/statistics/js/jquery.mockjax.js"></script>
<script type="text/javascript" src="${contextPath}/static/statistics/js/jquery.autocomplete.js"></script>
<script src=${contextPath}/static/layer/layui.all.js></script>
<script type="text/javascript">
    var SelectRowIndx;
    var grid_selector = "#grid-table";
    var pager_selector = "#grid-pager";

    var grid_shop_selector = "#grid-shop-table";
    var pager_shop_selector = "#grid-shop-pager";

    var grid_shop1_selector = "#grid-shop1-table";
    var pager_shop1_selector = "#grid-shop1-pager";

    var laypage = layui.laypage,
        layer = layui.layer
    laydate = layui.laydate;

    var queryModel = {
        //分页参数
        page: '1',
        rows: '10',
    }

    var app = new Vue({
        el: '#app',
        data: {
            objcte: [],
            yanType1: [],
            yanType2: [],
            yanType3: [],
            yanType4: [],
            yanType5: [],
            shopName: ''
        },
        methods: {
//            addProduct: function () {
//                shopInfo();
//                $('#myModal').modal('show');
//            }
        }
    })
    
</script>
<script>
    /**
     * 下啦联动数据绑定 开始代码
     * @type {{parentId: string}}
     */
    $('#isExpInput').change(function () {
        app.yanType2 = []
        app.yanType3 = []
        app.yanType4 = []
        $("#commodityScreen").addClass("hide");
        queryModel.parentId = $("#isExpInput option:selected").val();
        querySubProdType2()
    });

    $('#isAuthInput').change(function () {
        app.yanType3 = []
        app.yanType4 = []
        $("#commodityScreen").addClass("hide");
        queryModel.parentId = $("#isAuthInput option:selected").val();
        querySubProdType3()
    });

    $('#isAuthInput1').change(function () {
        app.yanType4 = []
        $("#commodityScreen").addClass("hide");
        queryModel.parentId = $("#isAuthInput1 option:selected").val();
        querySubProdType4()
    });

    $('#isAuthInput2').change(function () {
        app.yanType5 = []
        $("#commodityScreen").addClass("hide");
        queryModel.parentId = "";
        queryModel.typeId = $("#isAuthInput2 option:selected").val();
        querySubProdType5()
    });

    var querySubProdType1 = function () {
        getSubProdType1(queryModel)
    }
    var querySubProdType2 = function () {
        getSubProdType2(queryModel)
    }
    var querySubProdType3 = function () {
        getSubProdType3(queryModel)
    }
    var querySubProdType4 = function () {
        getSubProdType4(queryModel)
    }
    var querySubProdType5 = function () {
        getSubProdType5(queryModel)
    }


    var getSubProdType1 = function (queryModel) {
        // console.log(queryModel)

//        layer.load(1)
        $.ajax({
            url: '${contextPath}/ktProd/getSubProdType',
            type: 'post',
            data: queryModel,
            success: function (data) {
//                layer.closeAll('loading');
                if (data.success == false){
                    layer.msg("获取出错："+data.message)
                    return
                }
                var dataArray = data;

                if (dataArray.length == 0){
                    layer.msg("查询没有数据")
                    return
                }
//                 console.log("dataArray: "+dataArray)
                app.yanType1 = dataArray;

            },
            error: function (error) {
//                layer.closeAll('loading')
            }
        })
    }

    var getSubProdType2 = function (queryModel) {
        console.log(queryModel)
        $.ajax({
            url: '${contextPath}/ktProd/getSubProdType',
            type: 'post',
            data: queryModel,
            success: function (data) {
                if (data.success == false){
                    layer.msg("获取出错："+data.message)
                    return
                }
                var dataArray = data;

                if (dataArray.length == 0){
                    layer.msg("查询没有数据")
                    return
                }
                console.log("dataArray: "+dataArray)
                app.yanType2 = dataArray;

            },
            error: function (error) {
            }
        })
    }

    var getSubProdType3 = function (queryModel) {
        console.log(queryModel)
//        layer.load(1)
        $.ajax({
            url: '${contextPath}/ktProd/getSubProdType',
            type: 'post',
            data: queryModel,
            success: function (data) {
//                layer.closeAll('loading');
                if (data.success == false){
                    layer.msg("获取出错："+data.message)
                    return
                }
                var dataArray = data;

                if (dataArray.length == 0){
                    layer.msg("查询没有数据")
                    return
                }
//                console.log("dataArray: "+dataArray)
                app.yanType3 = dataArray;

            },
            error: function (error) {
//                layer.closeAll('loading')
            }
        })
    }

    var getSubProdType4 = function (queryModel) {
        // console.log(queryModel)
//        layer.load(1)
        $.ajax({
            url: '${contextPath}/ktProd/getSubProdType',
            type: 'post',
            data: queryModel,
            success: function (data) {
//                layer.closeAll('loading');
                if (data.success == false){
                    layer.msg("获取出错："+data.message)
                    return
                }
                var dataArray = data;

                if (dataArray.length == 0){
                    layer.msg("查询没有数据")
                    return
                }
//                console.log("dataArray: "+dataArray)
                app.yanType4 = dataArray;

            },
            error: function (error) {
//                layer.closeAll('loading')
            }
        })
    }

    var getSubProdType5 = function (queryModel) {
        // console.log(queryModel)
//        layer.load(1)
        $.ajax({
            url: '${contextPath}/ktProd/getProdProperty',
            type: 'post',
            data: queryModel,
            success: function (data) {
//                layer.closeAll('loading');
                if (data.success == false){
                    layer.msg("获取出错："+data.message)
                    return
                }
                var dataArray = data;

                if (dataArray.length == 0){
                    layer.msg("查询没有数据")
                    return
                }
                $("#commodityScreen").removeClass("hide");
                console.log("dataArray: "+dataArray)
                app.yanType5 = dataArray;

            },
            error: function (error) {
//                layer.closeAll('loading')
            }
        })
    }

    querySubProdType1(queryModel);

    /**
     * 下啦联动数据绑定 结束代码
     */
</script>

<script type="text/javascript" src="${contextPath}/static/ace/components/bootstrap-datepicker/dist/js/bootstrap-datepicker.js"></script>
<script type="text/javascript" src="${contextPath}/static/ace/components/jqGrid/js/jquery.jqGrid.js"></script>
<script type="text/javascript" src="${contextPath}/static/ace/components/jqGrid/js/i18n/grid.locale-cn.js"></script>
<script type="text/javascript" src="${contextPath}/static/layer/layer.js"></script>
<!-- 调拨订单详情 -->
<script>


    var grid_data = '${id}';
    console.log(grid_data)
    var scripts = [null, "${contextPath}/static/ace/components/bootstrap-datepicker/dist/js/bootstrap-datepicker.js", "${contextPath}/static/ace/components/jqGrid/js/jquery.jqGrid.js", "${contextPath}/static/ace/components/jqGrid/js/i18n/grid.locale-cn.js", "${contextPath}/static/layer/layer.js", null]
    $('.page-content-area').ace_ajax('loadScripts', scripts, function () {

        jQuery(function ($) {

            var parent_column = $(grid_selector).closest('[class*="col-"]');
            //resize to fit page size
            $(window).on('resize.jqGrid', function () {
                $(grid_selector).jqGrid('setGridWidth', parent_column.width());
            })

            //resize on sidebar collapse/expand
            $(document).on('settings.ace.jqGrid', function (ev, event_name, collapsed) {
                if (event_name === 'sidebar_collapsed' || event_name === 'main_container_fixed') {
                    //setTimeout is for webkit only to give time for DOM changes and then redraw!!!
                    setTimeout(function () {
                        $(grid_selector).jqGrid('setGridWidth', parent_column.width());
                    }, 20);
                }
            })

            jQuery(grid_selector).jqGrid({
                //direction: "rtl",

                //subgrid options
                subGrid: false,
                url: '${contextPath}/ktPurchase/getShopRequireOrderItems?id=${id}',
                data: grid_data,
                datatype: "json",
                mtype: 'POST',
                height: 350,
                colNames: ['商品Id', '商品编号','商品名称','调拨数量', '合计价格', '规格', '操作日期', '状态', '调拨方shopId', '调拨方', '发货方shopId', '发货方', '商品库存', 'requireId', 'requireOrderItemId'],
                colModel: [
                    {name: 'id', index: 'id', editable: true, hidden: true},
                    {
                        name: 'productCode', index: 'productCode', editable: true, hidden: false, align: 'left',
                        formatter:function(cellvalue, options, rowObject) {
                            var productCode = rowObject.productCode;
                            if(!productCode){
                                productCode = 0
                            }
                            return productCode;
                        }
                    },
                    {
                        name: 'productName', index: 'productName', editable: true, align: 'center',
                        formatter:function(cellvalue, options, rowObject) {
                            var productName = rowObject.productName;
                            if(!productName){
                                productName = 0
                            }
                            return productName;
                        }
                    },
                    {
                        name: 'quantity', index: 'quantity', editable: true, align: 'right',
                        formatter:function(cellvalue, options, rowObject) {
                            var quantity = rowObject.quantity;
                            if(!quantity){
                                quantity = 0
                            }
                            return quantity;
                        }
                    },
                    {
                        name: 'rtlPrice', index: 'rtlPrice', editable: true, align: 'right',
                        formatter:function(cellvalue, options, rowObject) {
                            var rtlPrice = rowObject.rtlPrice;
                            if(!rtlPrice){
                                rtlPrice = 0
                            }
                            return rtlPrice;
                        }
                    },
                    {
                        name: 'spec', index: 'spec', editable: true, align: 'right',
                        formatter:function(cellvalue, options, rowObject) {
                            var spec = rowObject.spec;
                            if(!spec){
                                spec = '-'
                            }
                            return spec;
                        }
                    },
                    {
                        name: 'stockSpec', index: 'stockSpec', editable: true,
                        formatter:function(cellvalue, options, rowObject) {
                            var stockSpec = rowObject.stockSpec;
                            if(!stockSpec){
                                stockSpec = '-'
                            }
                            return stockSpec;
                        }
                    },
                    {
                        name: 'status', index: 'status', editable: true,
                        formatter:function(cellvalue, options, rowObject) {
                            var status = rowObject.status;
                            if (status == "2"){
                                return "仓配";
                            }
                            if (status == "3"){
                                return "仓配完成";
                            }
                            if (status == "6"){
                                return "调拨";
                            }
                            return '待处理'
                        }
                    },
                    {
                        name: 'shopId',
                        index: 'shopId',
                        editable: true,
                        sortable: false,
                        hidden: true
                    },
                    {
                        name: 'shopName',
                        index: 'shopName',
                        editable: true,
                        sortable: false,
                        formatter:function(cellvalue, options, rowObject) {
                            var shopName = rowObject.shopName;
                            if(!shopName){
                                shopName = '-'
                            }
                            return shopName;
                        }
                    },
                    {
                        name: 'requireShopId',
                        index: 'requireShopId',
                        editable: true,
                        hidden:true,
                        sortable: false,
//                        formatter:function(cellvalue, options, rowObject) {
//                            var ss = rowObject.ss;
//                            return '<div id="requireShopId_'+rowObject.productId+'">'+rowObject.requireShopId+'</div>';
//                        }
                    },
                    {
                        name: 'requireShopName',
                        index: 'requireShopName',
                        editable: true,
                        sortable: false,
                        formatter:function(cellvalue, options, rowObject) {
                            var requireShopName = rowObject.requireShopName;
                            if(!requireShopName){
                                requireShopName = '-'
                            }
                            return requireShopName;
                        }
                    },
                    {
                        name: 'stock',
                        index: 'stock',
                        editable: true,
//                        hidden:true,
                        sortable: false,
                        align: 'right',
                        formatter:function(cellvalue, options, rowObject) {
                            var stock = rowObject.stock;
                            if(!stock){
                                stock = 0;
                            }
                            return stock;
                        }
                    },
                    {
                        name: 'requireId',
                        index: 'requireId',
                        editable: true,
                        hidden:true,
                        sortable: false,
                        align: 'right',
                    },
                    {
                        name: 'requireOrderItemId',
                        index: 'requireOrderItemId',
                        editable: true,
                        hidden:true,
                        sortable: false,
                        align: 'right',
                    },
                ],

                rownumbers: true, //自动行数
//                height:"100%",   //高度自适应
//			width: "100%",
                autowidth: true,  //宽度自适应
                viewrecords: true,
                rowNum: 100000000,
//                rowList: [10, 20, 30],
//                pager: pager_selector,
                altRows: true,
                //toppager: true,

                multiselect: false,
                //multikey: "ctrlKey",
                multiboxonly: false,

                loadComplete: function () {
                    var table = this;
                    setTimeout(function () {
                        styleCheckbox(table);

                        updateActionIcons(table);
                        updatePagerIcons(table);
                        enableTooltips(table);
                    }, 0);
                },

//                onSelectRow: function () {
//                    SelectRowIndx = GetJqGridRowIndx("#" + this.id);
//                },
                gridComplete: function () {
                    var ids = $(grid_selector).getDataIDs();
                    for (var i = 0; i < ids.length; i++) {
                        var rowData = $(grid_selector).getRowData(ids[i]);

                        console.log(rowData)

                        var quantity = rowData.quantity;
                        var stock = rowData.stock;

                        console.log(quantity)
                        console.log(quantity  > stock)
                        if ( stock == 0 || quantity  > stock) {//如果审核不通过，则背景色置于红色
                            console.log(ids[i])
                            $('#' + ids[i]).removeClass("ui-priority-secondary")
                            $('#' + ids[i]).addClass("SelectBG");
                        }
                    }

                    $("#" + this.id).jqGrid('setSelection', SelectRowIndx);
                },
//                ondblClickRow: function () {
//                    var id = $(grid_selector).jqGrid('getGridParam', 'selrow');
//                    var rowData = $(grid_selector).jqGrid('getRowData', id);
//
//                    pageInit(rowData.productId)
//                    $('#myModal1').modal('show');
//                },

                editurl: "${contextPath}/ktPurchase/saveSupplier",//nothing is saved
                caption: "调拨单商品详情",
                jsonReader: {
                    root: "recordList",
                    page: "currentPage",
                    total: "pageCount",
                    records: "recordCount"
                }

                //,autowidth: true,

                /**
                 ,
                 grouping:true,
                 groupingView : {
				 groupField : ['name'],
				 groupDataSorted : true,
				 plusicon : 'fa fa-chevron-down bigger-110',
				 minusicon : 'fa fa-chevron-up bigger-110'
			},
                 caption: "Grouping"
                 */

            });

            $(window).triggerHandler('resize.jqGrid');//trigger window resize to make the grid get the correct size

            $("#addProduct").click(function () {
                var orderId = '${id}';
                if(orderId){
                    var id = $(grid_selector).jqGrid('getGridParam', 'selrow');

                    var rowData = $(grid_selector).jqGrid('getRowData', id);
                    if (!id) {
                        $.jgrid.info_dialog("提示：", "请选择一条信息");
                        return;
                    }
                    if(rowData.state != "待提交"){
                        $.jgrid.info_dialog("提示：", "订单已提交不能修改");
                        return;
                    }
                }
                shopInfo()
            })

            /**
             * 修改某条信息
             */
            $("#editShop").click(function () {
                var id = $(grid_selector).jqGrid('getGridParam', 'selrow');

                var rowData = $(grid_selector).jqGrid('getRowData', id);
                if (!id) {
                    $.jgrid.info_dialog("提示：", "请选择一条信息");
                    return;
                }
                if(rowData.state != "待提交"){
                    $.jgrid.info_dialog("提示：", "订单已提交不能修改");
                    return;
                }
                $(grid_selector).jqGrid("editGridRow", id, {
                    // edit record form
                    width: 500,
                    closeAfterEdit: true,
                    //editData :
                    recreateForm: true,
                    viewPagerButtons: false,
                    beforeShowForm: function (e) {
                        var form = $(e[0]);
                        form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar')
                            .wrapInner('<div class="widget-header" />');
                        style_edit_form(form);
                    },
                    afterShowForm: function (e) {
                        var form = $(e[0]);
                        //console.log(form)
                    },
                    afterSubmit: function (response, postdata) {
                        var result = eval('(' + response.responseText + ')');
                        ////console.log(result);
                        return [result.success, result.message, 0];
                    },
                    errorTextFormat: function (response) {
                        ////console.log("错误"+response.responseText);
                        //var result = response.responseText;
                        return "服务器异常，稍后再试";
                    }
                });
            });
//            $("#editShop").click(function () {
//                alert(1234567);
//                var id = $(grid_selector).jqGrid('getGridParam', 'selrow');
//                if (!id) {
//                    $.jgrid.info_dialog("提示：", "请选择一条信息");
//                    return;
//                }
//
//                var rowData = $(grid_selector).jqGrid('getRowData', id);
////                console.log(rowData.id);
////                layer.load(1);
//
//                getSupplier(rowData);
//                reload();
//
//            });

            /**
             * 删除某条数据
             */
            $("#deleteSupplier").click(function () {
                var id = $(grid_selector).jqGrid('getGridParam', 'selrow');

                if (!id) {
                    layer.msg("提示：请选择一条信息");
                    return;
                }
//询问框
                layer.confirm('将会把这条商品数据删除', {
                    btn: ['确定', '取消'] //按钮
                }, function () {
                    var rowData = $(grid_selector).jqGrid('getRowData', id);
//                    rowData.id = rowData.id.split('>')[1].split('<')[0];
                    queryModel.id = rowData.id;
                    layer.load(1);
                    $.ajax({
                        url: '${contextPath}/',
                        type: 'post',
                        data: queryModel,
                        dataType: 'json',
                        success: function (data) {
                            layer.closeAll('loading');
                            if (data.success) {
                                layer.msg('删除成功', {icon: 1});

                            } else {
                                layer.msg(data.message);
                            }
                            reload();

                        },
                        error: function (error) {
                            layer.closeAll('loading');
                            $.jgrid.info_dialog("提示：", "服务器异常，稍后再试");
                        }

                    })

                }, function () {
                });
            });

            //测试
//            $("#cot").click(function () {
//                jQuery(grid_selector).setGridParam().showCol("cot").trigger("reloadGrid");
//            })

        });
    });
    //修改调用
    var getSupplier = function (rowData) {
        queryModel.id = rowData.id;
//        console.log(queryModel)
        layer.load(1)
        $.ajax({
            url: '${contextPath}/ktPurchase/getSupplier',
            type: 'post',
            data: queryModel,
            success: function (data) {
                layer.closeAll('loading');
                if (data.success == false){
                    layer.msg("获取出错："+data.message)
                    return
                }
                var dataArray = data.data;
                if (dataArray.length == 0){
                    layer.msg("查询没有数据")
                    return
                }
//                console.log(dataArray)
                editShop(dataArray);
            },
            error: function (error) {
                layer.closeAll('loading')
            }
        })
    };
</script>
<!-- 商品列表详情 -->
<script>
    var shopInfo = function() {
        $('#myModal').modal('show');
        jQuery(grid_shop_selector).jqGrid({
            subGrid: false,
            url : '${contextPath}/ktProd/getProdInfo',
            datatype: "json",
            mtype: 'POST',
            height: 300,
            colNames: ['ID', '商品名称', '供应名称', '类型', '条码','状态','单位','规格', '操作时间'],
            colModel: [
                {name: 'productId', index: 'productId', width: 30, editable: true},
                {
                    name: 'productName',
                    index: 'productName',
                    width: 90,
                    editable: true,
                    sortable: false,
                    editrules: {required: true}
                },
//                    {name: 'supplierId', index: 'productId', width: 60, editable: true},
                {
                    name: 'supplierName', index: 'productId', width: 78, editable: true,
                    edittype: 'select'
                },
                {
                    name: 'prodTypeName',
                    index: 'prodTypeName',
                    width: 60,
                    editable: true,
                    sortable: false,
                    editrules: {required: true}
                },
                {
                    name: 'productCode',
                    index: 'productCode',
                    width: 60,
                    editable: true,
                    sortable: false,
                    editrules: {required: true}
                },

                {
                    name: 'state',
                    index: 'state',
                    width: 40,
                    editable: true,
                    sortable: false,
                    edittype: 'select',
                    formatter: function (v, x, r) {
                        return r['state'] == "1" ? "有效" : "无效";
                    },
                    editoptions: {value: "0:有效;1:无效"}
                },
                {
                    name: 'unit',
                    index: 'unit',
                    width: 30,
                    editable: true,
                    sortable: false
                },{
                    name: 'spec',
                    index: 'spec',
                    width: 60,
                    editable: true,
                    sortable: false
                },
                {name: 'stateDate', index: 'stateDate', width: 60, editable: false}

            ],
//                rownumbers: true, //自动行数
            height:"100%",   //高度自适应
//			width: "100%",
            autowidth: true,  //宽度自适应
            viewrecords: true,
            rowNum: 10,
            rowList: [10, 20, 30],
            pager: pager_shop_selector,
            altRows: true,
            //toppager: true,

            multiselect: true,
            //multikey: "ctrlKey",
            multiboxonly: false,

            loadComplete: function () {
                var table = this;
                setTimeout(function () {
                    styleCheckbox(table);

                    updateActionIcons(table);
                    updatePagerIcons(table);
                    enableTooltips(table);
                }, 0);
            },

            editurl: "${contextPath}/ktProd/getShopListByPage",//nothing is saved
            caption: "店铺列表",
            jsonReader: {
                root: "recordList",
                page: "currentPage",
                total: "pageCount",
                records: "recordCount"
            },
//                onSelectAll: function(rowids,statue){
//                    //函数里做自己的处理
//					queryModel.rowIds = rowids;
//                },
//                resetSelection: function(rowid){
//
//                    return(rowid)
//				}

            //,autowidth: true,


            /**
             ,
             grouping:true,
             groupingView : {
				 groupField : ['name'],
				 groupDataSorted : true,
				 plusicon : 'fa fa-chevron-down bigger-110',
				 minusicon : 'fa fa-chevron-up bigger-110'
			},
             caption: "Grouping"
             */

        });
        //it causes some flicker when reloading or navigating grid
        //it may be possible to have some custom formatter to do this as the grid is being created to prevent this
        //or go back to default browser checkbox styles for the grid
        function styleCheckbox(table) {
            /**
             $(table).find('input:checkbox').addClass('ace')
             .wrap('<label />')
             .after('<span class="lbl align-top" />')


             $('.ui-jqgrid-labels th[id*="_cb"]:first-child')
             .find('input.cbox[type=checkbox]').addClass('ace')
             .wrap('<label />').after('<span class="lbl align-top" />');
             */
        }


        //unlike navButtons icons, action icons in rows seem to be hard-coded
        //you can change them like this in here if you want
        function updateActionIcons(table) {
            /**
             var replacement =
             {
                 'ui-ace-icon fa fa-pencil' : 'ace-icon fa fa-pencil blue',
                 'ui-ace-icon fa fa-trash-o' : 'ace-icon fa fa-trash-o red',
                 'ui-icon-disk' : 'ace-icon fa fa-check green',
                 'ui-icon-cancel' : 'ace-icon fa fa-times red'
             };
             $(table).find('.ui-pg-div span.ui-icon').each(function(){
				var icon = $(this);
				var $class = $.trim(icon.attr('class').replace('ui-icon', ''));
				if($class in replacement) icon.attr('class', 'ui-icon '+replacement[$class]);
			})
             */
        }

        //replace icons with FontAwesome icons like above
        function updatePagerIcons(table) {
            var replacement =
                {
                    'ui-icon-seek-first': 'ace-icon fa fa-angle-double-left bigger-140',
                    'ui-icon-seek-prev': 'ace-icon fa fa-angle-left bigger-140',
                    'ui-icon-seek-next': 'ace-icon fa fa-angle-right bigger-140',
                    'ui-icon-seek-end': 'ace-icon fa fa-angle-double-right bigger-140'
                };
            $('.ui-pg-table:not(.navtable) > tbody > tr > .ui-pg-button > .ui-icon').each(function () {
                var icon = $(this);
                var $class = $.trim(icon.attr('class').replace('ui-icon', ''));

                if ($class in replacement) icon.attr('class', 'ui-icon ' + replacement[$class]);
            })
        }

        function enableTooltips(table) {
            $('.navtable .ui-pg-button').tooltip({container: 'body'});
            $(table).find('.ui-pg-div').tooltip({container: 'body'});
        }

        //var selr = jQuery(grid_selector).jqGrid('getGridParam','selrow');

        $(document).one('ajaxloadstart.page', function (e) {
            $.jgrid.gridDestroy(grid_selector);
            $('.ui-jqdialog').remove();
        });

        $(window).triggerHandler('resize.jqGrid');//trigger window resize to make the grid get the correct size

    }
</script>
<script type="text/javascript">

    /**
     * 搜索店铺
     */
    function searchShop() {
        var keyword = $("#keyword").val();
//        var phone = $("#phone").val();
        //var parentDepartmentkey = $("#id_parentDepartmentkey_name").val();

        var filters = {
            "rules": [{
                "field": "keyword",
                "data": keyword
            }]
        };
        jQuery("#grid-table").jqGrid('setGridParam', {
            postData: {
                "filters": JSON.stringify(filters) //"{'rules' : [{'field' : 'shopName','data' : "+shopName+"},{'field' : 'state','data' : "+state+"}]}"
            }
        }).trigger("reloadGrid");
    }


    var reload = function () {
//        $(grid_selector).jqGrid('clearGridData');  //清空表格
        $(grid_selector).jqGrid('setGridParam',{
            url:"${contextPath}/ktPurchase/getShopRequireOrderItems?id=${id}",
            datatype:'json',
//                    postData:param,
            page:1
        }).trigger("reloadGrid"); //重新载入
    }

</script>
<script type="application/javascript">
    function style_edit_form(form) {
        //enable datepicker on "sdate" field and switches for "stock" field
        //form.find('input[name=sdate]').datepicker({format:'yyyy-mm-dd' , autoclose:true})

        //form.find('input[name=stock]').addClass('ace ace-switch ace-switch-5').after('<span class="lbl"></span>');
        //don't wrap inside a label element, the checkbox value won't be submitted (POST'ed)
        //.addClass('ace ace-switch ace-switch-5').wrap('<label class="inline" />').after('<span class="lbl"></span>');


        //update buttons classes
        var buttons = form.next().find('.EditButton .fm-button');
        buttons.addClass('btn btn-sm').find('[class*="-icon"]').hide();//ui-icon, s-icon
        buttons.eq(0).addClass('btn-primary').prepend('<i class="ace-icon fa fa-check"></i>');
        buttons.eq(1).prepend('<i class="ace-icon fa fa-times"></i>')

        buttons = form.next().find('.navButton a');
        buttons.find('.ui-icon').hide();
        buttons.eq(0).append('<i class="ace-icon fa fa-chevron-left"></i>');
        buttons.eq(1).append('<i class="ace-icon fa fa-chevron-right"></i>');
    }

    function style_delete_form(form) {
        var buttons = form.next().find('.EditButton .fm-button');
        buttons.addClass('btn btn-sm btn-white btn-round').find('[class*="-icon"]').hide();//ui-icon, s-icon
        buttons.eq(0).addClass('btn-danger').prepend('<i class="ace-icon fa fa-trash-o"></i>');
        buttons.eq(1).addClass('btn-default').prepend('<i class="ace-icon fa fa-times"></i>')
    }

    function style_search_filters(form) {
        form.find('.delete-rule').val('X');
        form.find('.add-rule').addClass('btn btn-xs btn-primary');
        form.find('.add-group').addClass('btn btn-xs btn-success');
        form.find('.delete-group').addClass('btn btn-xs btn-danger');
    }

    function style_search_form(form) {
        var dialog = form.closest('.ui-jqdialog');
        var buttons = dialog.find('.EditTable')
        buttons.find('.EditButton a[id*="_reset"]').addClass('btn btn-sm btn-info').find('.ui-icon').attr('class', 'ace-icon fa fa-retweet');
        buttons.find('.EditButton a[id*="_query"]').addClass('btn btn-sm btn-inverse').find('.ui-icon').attr('class', 'ace-icon fa fa-comment-o');
        buttons.find('.EditButton a[id*="_search"]').addClass('btn btn-sm btn-purple').find('.ui-icon').attr('class', 'ace-icon fa fa-search');
    }

    function beforeDeleteCallback(e) {
        var form = $(e[0]);
        if (form.data('styled')) return false;

        form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
        style_delete_form(form);
        form.data('styled', true);
    }

    function beforeEditCallback(e) {
        var form = $(e[0]);
        form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
        style_edit_form(form);
    }


    //it causes some flicker when reloading or navigating grid
    //it may be possible to have some custom formatter to do this as the grid is being created to prevent this
    //or go back to default browser checkbox styles for the grid
    function styleCheckbox(table) {
        /**
         $(table).find('input:checkbox').addClass('ace')
         .wrap('<label />')
         .after('<span class="lbl align-top" />')


         $('.ui-jqgrid-labels th[id*="_cb"]:first-child')
         .find('input.cbox[type=checkbox]').addClass('ace')
         .wrap('<label />').after('<span class="lbl align-top" />');
         */
    }


    //unlike navButtons icons, action icons in rows seem to be hard-coded
    //you can change them like this in here if you want
    function updateActionIcons(table) {
        /**
         var replacement =
         {
             'ui-ace-icon fa fa-pencil' : 'ace-icon fa fa-pencil blue',
             'ui-ace-icon fa fa-trash-o' : 'ace-icon fa fa-trash-o red',
             'ui-icon-disk' : 'ace-icon fa fa-check green',
             'ui-icon-cancel' : 'ace-icon fa fa-times red'
         };
         $(table).find('.ui-pg-div span.ui-icon').each(function(){
				var icon = $(this);
				var $class = $.trim(icon.attr('class').replace('ui-icon', ''));
				if($class in replacement) icon.attr('class', 'ui-icon '+replacement[$class]);
			})
         */
    }

    //replace icons with FontAwesome icons like above
    function updatePagerIcons(table) {
        var replacement =
            {
                'ui-icon-seek-first': 'ace-icon fa fa-angle-double-left bigger-140',
                'ui-icon-seek-prev': 'ace-icon fa fa-angle-left bigger-140',
                'ui-icon-seek-next': 'ace-icon fa fa-angle-right bigger-140',
                'ui-icon-seek-end': 'ace-icon fa fa-angle-double-right bigger-140'
            };
        $('.ui-pg-table:not(.navtable) > tbody > tr > .ui-pg-button > .ui-icon').each(function () {
            var icon = $(this);
            var $class = $.trim(icon.attr('class').replace('ui-icon', ''));

            if ($class in replacement) icon.attr('class', 'ui-icon ' + replacement[$class]);
        })
    }

    function enableTooltips(table) {
        $('.navtable .ui-pg-button').tooltip({container: 'body'});
        $(table).find('.ui-pg-div').tooltip({container: 'body'});
    }

    //var selr = jQuery(grid_selector).jqGrid('getGridParam','selrow');

    $(document).one('ajaxloadstart.page', function (e) {
        $.jgrid.gridDestroy(grid_selector);
        $('.ui-jqdialog').remove();
    });

</script>
<!-- 店铺加载 -->
<script type="text/javascript">
    // 加载店铺列表

    function pageInit(productId){
        console.log(productId)
        jQuery(grid_shop_selector).jqGrid({
            subGrid: false,
            url : '${contextPath}/ktProd/getShopListByPage',
            datatype: "json",
            mtype: 'POST',
            height: 300,
            colNames: ['店铺编号', '店铺名称'],
            colModel: [
                {name: 'shopId', index: 'shopId', width: 200, editable: true, key: true},
//                    {
//                        name: 'row',
//                        index: 'row',
//                        width: 90,
//                        editable: true,
//                        sortable: false,
//                        editrules: {required: true}
//                    },
                {
                    name: 'shopName',
                    index: 'shopName',
                    width: 310,
                    editable: true,
                    sortable: false,
                    editrules: {required: true}
                }

            ],
//                rownumbers: true, //自动行数
            height:"100%",   //高度自适应
//			width: "100%",
            autowidth: true,  //宽度自适应
//            viewrecords: true,
            rowNum: 10,
            rowList: [10, 20, 30],
            pager: pager_shop_selector,
            altRows: true,
            //toppager: true,

            multiselect: true,
            //multikey: "ctrlKey",
            multiboxonly: false,

            loadComplete: function () {
                var table = this;
                setTimeout(function () {
                    styleCheckbox(table);

                    updateActionIcons(table);
                    updatePagerIcons(table);
                    enableTooltips(table);
                }, 0);
            },

            editurl: "${contextPath}/ktProd/getShopListByPage",//nothing is saved
            caption: "店铺列表",
            jsonReader: {
                root: "recordList",
                page: "currentPage",
                total: "pageCount",
                records: "recordCount"
            },
            ondblClickRow: function () {
                var shopId = $(grid_shop_selector).jqGrid('getGridParam', 'selrow');
                var rowData = $(grid_shop_selector).jqGrid('getRowData', shopId);

                var shopId = $("#shopId").val();
                if (shopId == rowData.shopId){
                    layer.msg("提示：商品来源不能选择自己")
                    return
                }
                ssaa(rowData)
                $('#myModal1').modal('hide');
            }

//                onSelectAll: function(rowids,statue){
//                    //函数里做自己的处理
//					queryModel.rowIds = rowids;
//                },
//                resetSelection: function(rowid){
//
//                    return(rowid)
//				}

            //,autowidth: true,


            /**
             ,
             grouping:true,
             groupingView : {
				 groupField : ['name'],
				 groupDataSorted : true,
				 plusicon : 'fa fa-chevron-down bigger-110',
				 minusicon : 'fa fa-chevron-up bigger-110'
			},
             caption: "Grouping"
             */

        });
        //it causes some flicker when reloading or navigating grid
        //it may be possible to have some custom formatter to do this as the grid is being created to prevent this
        //or go back to default browser checkbox styles for the grid
        function styleCheckbox(table) {
            /**
             $(table).find('input:checkbox').addClass('ace')
             .wrap('<label />')
             .after('<span class="lbl align-top" />')


             $('.ui-jqgrid-labels th[id*="_cb"]:first-child')
             .find('input.cbox[type=checkbox]').addClass('ace')
             .wrap('<label />').after('<span class="lbl align-top" />');
             */
        }


        //unlike navButtons icons, action icons in rows seem to be hard-coded
        //you can change them like this in here if you want
        function updateActionIcons(table) {
            /**
             var replacement =
             {
                 'ui-ace-icon fa fa-pencil' : 'ace-icon fa fa-pencil blue',
                 'ui-ace-icon fa fa-trash-o' : 'ace-icon fa fa-trash-o red',
                 'ui-icon-disk' : 'ace-icon fa fa-check green',
                 'ui-icon-cancel' : 'ace-icon fa fa-times red'
             };
             $(table).find('.ui-pg-div span.ui-icon').each(function(){
				var icon = $(this);
				var $class = $.trim(icon.attr('class').replace('ui-icon', ''));
				if($class in replacement) icon.attr('class', 'ui-icon '+replacement[$class]);
			})
             */
        }

        //replace icons with FontAwesome icons like above
        function updatePagerIcons(table) {
            var replacement =
                {
                    'ui-icon-seek-first': 'ace-icon fa fa-angle-double-left bigger-140',
                    'ui-icon-seek-prev': 'ace-icon fa fa-angle-left bigger-140',
                    'ui-icon-seek-next': 'ace-icon fa fa-angle-right bigger-140',
                    'ui-icon-seek-end': 'ace-icon fa fa-angle-double-right bigger-140'
                };
            $('.ui-pg-table:not(.navtable) > tbody > tr > .ui-pg-button > .ui-icon').each(function () {
                var icon = $(this);
                var $class = $.trim(icon.attr('class').replace('ui-icon', ''));

                if ($class in replacement) icon.attr('class', 'ui-icon ' + replacement[$class]);
            })
        }

        function enableTooltips(table) {
            $('.navtable .ui-pg-button').tooltip({container: 'body'});
            $(table).find('.ui-pg-div').tooltip({container: 'body'});
        }

        //var selr = jQuery(grid_selector).jqGrid('getGridParam','selrow');

        $(document).one('ajaxloadstart.page', function (e) {
            $.jgrid.gridDestroy(grid_selector);
            $('.ui-jqdialog').remove();
        });

        $(window).triggerHandler('resize.jqGrid');//trigger window resize to make the grid get the correct size
    }

    var ssaa = function (rowData) {
        $(requireShopName).html(rowData.shopName);
        $(requireShopId).html(rowData.shopId);
    }
</script>
<!-- 业务 -->
<script>
    //直配
    $("#zhip").click(function () {
        var ids = $(grid_selector).jqGrid('getGridParam', 'selarrrow');
        if (ids.length == 0){
            layer.msg("你没有选择添加商品！");
            return;
        }

        var prodList = [];
        for(var i=0;i<ids.length;i++){
            var rowData = $(grid_selector).jqGrid('getRowData', ids[i]);
            if(rowData.status != '待处理'){
                layer.msg("提示：商品已经处理过了，不能重复处理")
                return
            }
            var requireShopId = rowData.requireShopId;

            if(requireShopId != '0'){
                layer.msg("提示：出货方是总部的才能直配")
                return
            }
            var idArray = {};
            idArray.productCode = rowData.productCode;
            var quantity = rowData.quantity;
            idArray.shopId = rowData.shopId;
            idArray.quantity = quantity;
            idArray.requireShopId = requireShopId;
            idArray.requireId = rowData.requireId;
            idArray.requireOrderItemId = rowData.requireOrderItemId;
            prodList.push(idArray);
            queryModel.shopId = rowData.shopId;
            queryModel.requireShopId = rowData.requireShopId;
        }
        prodList.id = idArray;
        queryModel.prodList = JSON.stringify(prodList);
        queryModel.requireId = '${id}';
        queryModel.type = '2';
        console.log(queryModel)
        $.ajax({
            url: '${contextPath}/ktPurchase/createInOutStockOrder',
            type: 'post',
            data: queryModel,
            success: function (data) {
//                layer.closeAll('loading');
                if (data.success == false){
                    layer.msg("获取出错："+data.message)
                    return
                }
                var dataArray = data;
                layer.msg("提示："+data.message)
                reload()
            },
            error: function (error) {
//                layer.closeAll('loading')
            }
        })
    });

    //调拨
    $("#diaob").click(function () {
        layer.load(1)
        var ids = $(grid_selector).getDataIDs();
        if (ids.length == 0){
            layer.closeAll('loading');
            layer.msg("你没有选择添加商品！");
            return;
        }
        var prodList = [];
        var shopName = '';
        for(var i=0;i<ids.length;i++){
            var rowData = $(grid_selector).jqGrid('getRowData', ids[i]);

            if(rowData.status != '待处理'){
                layer.closeAll('loading');
                layer.msg("提示：商品已经处理过了，不能重复处理")
                return
            }
            var requireShopId = rowData.requireShopId
            console.log(requireShopId)
            if(requireShopId == '0'){
                layer.closeAll('loading');
                layer.msg("提示：出货方是门店的才能调拨")
                return
            }
            if(shopName != '') {
                var shop = rowData.shopName;
                if (shopName != shop) {
                    layer.closeAll('loading');
                    layer.msg("提示：商品来源相同才能调拨")
                    return
                }
            }
            var idArray = {};
            var quantity = rowData.quantity;

            shopName = rowData.shopName;

            idArray.productCode = rowData.productCode;
            idArray.requireShopId = requireShopId;
            idArray.shopId = rowData.shopId;
            idArray.quantity = quantity;
            idArray.requireId = rowData.requireId;
            idArray.requireOrderItemId = rowData.requireOrderItemId;
            prodList.push(idArray);

            queryModel.requireShopId = rowData.requireShopId;
            queryModel.shopId = rowData.shopId;
        }
        prodList.id = idArray;
        queryModel.prodList = JSON.stringify(prodList);
        queryModel.type = '6';
        queryModel.requireId = '${id}';
        console.log(queryModel)
        $.ajax({
            url: '${contextPath}/ktPurchase/createInOutStockOrder',
            type: 'post',
            data: queryModel,
            success: function (data) {
                layer.closeAll('loading');
                if (data.success == false){
                    layer.msg("获取出错："+data.message)
                    return
                }
                var dataArray = data;
                layer.msg("提示："+data.message)
                reload()
            },
            error: function (error) {
                layer.closeAll('loading')
            }
        })
    });

    //发起调拨
    $("#faqi").click(function () {
        layer.load(1)
        var id = $(grid_selector).jqGrid('getGridParam', 'selrow');
        if(!id){
            layer.closeAll('loading');
            layer.msg("提示：请选择商品")
            return
        }
        var rowData = $(grid_selector).jqGrid('getRowData', id);
        //订单Id
        var orderId = '${id}';
        queryModel.id = orderId;
        queryModel.state = '1';
        console.log(queryModel)
        $.ajax({
            url: '${contextPath}/ktPurchase/shopRequireOrderCheck',
            type: 'post',
            data: queryModel,
            success: function (data) {
                layer.closeAll('loading');
                if (data.success == false){
                    layer.msg("获取出错："+data.message)
                    return
                }
                var dataArray = data;
                layer.msg("提示："+data.message)
                reload()
            },
            error: function (error) {
                layer.closeAll('loading')
            }
        })
    });
</script>